package project.dade.cn.bst.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.Toast;

import cn.jpush.android.api.JPushInterface;
import project.dade.cn.bst.MainActivity;
import project.dade.cn.bst.R;
import project.dade.cn.bst.manager.AppApplication;

/**
 * Created by vain zhou on 2015/9/21.
 */
public class SplashActivity extends AppCompatActivity {

    private static final int GO_HOME = 1000;
    // 延迟3秒
    private static final long SPLASH_DELAY_MILLIS = 3000;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        boolean homeStartUp = AppApplication.getInstance().getSpUtil().getBoolean(this,
                "HomeStartUp", false);//存储这个值
        // Toast.makeText(this, homeStartUp + "", Toast.LENGTH_LONG).show();
        if (!homeStartUp) {
            startActivity(new Intent(this, GuideActivity.class));
        } else {
            setContentView(R.layout.activity_splash);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS);

        }
    }
    /*
     * Handler:跳转到不同界面
     */
    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case GO_HOME:
                    goMain();
                    break;
            }
            super.handleMessage(msg);
        }
    };

    private void goMain() {
        Intent mIntent = new Intent(SplashActivity.this, MainActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(mIntent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

}
